<template>
  <el-form :model="changePass" :rules="rules" ref="changePass">
    <el-form-item label="登录密码" prop="pass" label-width="130px">
      <el-input
        type="password"
        v-model="changePass.pass"
        autocomplete="off"
        show-password
      ></el-input>
    </el-form-item>
    <el-form-item label="重复登录密码" prop="password" label-width="130px">
      <el-input
        type="password"
        v-model="changePass.checkPass"
        autocomplete="off"
        show-password
      ></el-input>
    </el-form-item>
  </el-form>
</template>

<script>
export default {
  data() {
    var validatePass = (rule, value, callback) => {
      if (value === "") {
        callback(new Error("请输入密码"));
      } else {
        if (this.ruleForm.checkPass !== "") {
          this.$refs.ruleForm.validateField("checkPass");
        }
        callback();
      }
    };
    var validatePass2 = (rule, value, callback) => {
      if (value === "") {
        callback(new Error("请再次输入密码"));
      } else if (value !== this.ruleForm.pass) {
        callback(new Error("两次输入密码不一致!"));
      } else {
        callback();
      }
    };
    return {
      ruleForm: {
        pass: "",
        checkPass: "",
        age: "",
      },
      rules: {
        pass: [{ validator: validatePass, trigger: "blur" }],
        checkPass: [{ validator: validatePass2, trigger: "blur" }],
      },
    };
  },
  props: {
    changePass: Object,
  },
};
</script>

<style>
</style>